package com.bw.visitor.net

import androidx.lifecycle.MutableLiveData
import com.bw.common.vm.BaseViewModel
import com.bw.http.utils.zgr.OkHttpClientManager
import com.bw.visitor.entity.VisitorEntity

class VisitorViewModel:BaseViewModel() {
    private val apiService = OkHttpClientManager.retrofitInstance.create(ApiService::class.java)

    val visitorSuccess by lazy { MutableLiveData<List<VisitorEntity>>() }
    fun getVisitor(){
        executeNetwork(
            {apiService.getVisitor()},
            visitorSuccess::postValue
        )
    }

    val addVisitorSuccess by lazy { MutableLiveData<VisitorEntity>() }

    fun addVisitor(visitorEntity: VisitorEntity) {
        executeNetwork(
            {apiService.addVisitor(visitorEntity)},
            addVisitorSuccess::postValue
        )
    }

    val deleteVisitorSuccess by lazy { MutableLiveData<String>() }
    fun deleteVisitor(id:Int) {
        executeNetwork(
            {apiService.deleteVisitor(id)},
            deleteVisitorSuccess::postValue
        )
    }

}